package com.nowcoder.community.util;/**
 * @description:
 * @Author HP
 * @create 2021/12/14 20:47
 */

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @author HP
 * @create 2021-12-14 20:47
 * @desc 用于处理cookie的工具类
 **/
public class CookieUtil {
    public static String getValue(HttpServletRequest request, String name){
        if(request==null||name==null)  {
            throw new IllegalArgumentException("参数为空");
        }
        Cookie[]cookies= request.getCookies();
        if (cookies!=null){
            for (Cookie ck:cookies){
                if(ck.getName().equals(name)){
                    return ck.getValue();
                }
            }
        }
        return null;
    }
}
